home *** CD-ROM | disk | FTP | other *** search
/ Underground / Underground CD1.iso / virii / zrodla / m / move.asm < prev    next >
Encoding:
Assembly Source File  |  1998-01-14  |  8.8 KB  |  150 lines

  1. CODE_SEG        SEGMENT
  2.  
  3.         ORG     100H                    ;ORG 100H for a .com file
  4.  
  5.         ASSUME  CS:CODE_SEG,DS:CODE_SEG
  6.  
  7. FIRST:  JMP     ENTRY                   ;Skip over data area
  8.  
  9.         COPYRIGHT       DB      '(C) S. HOLZNER 1984'
  10.  
  11.         TARGET_FCB      DB      37 DUP(0) ;FCB at 6CH will be written over
  12.  
  13.         END_FLAG        DW      0               ;Flag set after everything read
  14.  
  15.         FILE_SIZE_LO    DW      0               ;Low word of file size, in bytes
  16.  
  17.         FILE_SIZE_HI    DW      0               ;High word of same
  18.  
  19.         FILE_SIZE_K     DW      0               ;Number of Clusters to write
  20.  
  21.         DTA_OFFSET      DW      0               ;Used for 1K increments into DTA
  22.  
  23.         COPY_MSG_1      DB      13,10,'Copy $'  ;Part 1 of the copy prompt
  24.  
  25.         COPY_MSG_2      DB      ' (Y/N)?$'      ;And part 2
  26.  
  27.         FULL_MSG        DB      13,10,'Disk Full$'      ;Trouble message
  28.  
  29.  
  30.  
  31. MOVE    PROC    NEAR                    ;The main (and only) procedure
  32.  
  33. ENTRY:  MOV     CX,32                   ;Copy over 1st 32 bytes of default DTA
  34.  
  35.         MOV     SI,6CH                  ; from 6CH into Target_FCB area for 
  36.  
  37.         LEA     DI,TARGET_FCB           ; later use as new file name
  38.  
  39. REP     MOVSB
  40.  
  41.         MOV     DX,5CH                  ;The source FCB
  42.  
  43.         MOV     AH,11H                  ;Check if there is match to source file
  44.  
  45.         INT     21H
  46.  
  47.         CMP     AL,0FFH                 ;0FFH -> No match
  48.  
  49.         JNE     QUERY                   ;Match
  50.  
  51.         JMP     OUT                     ;No Match
  52.  
  53. QUERY:  MOV     AH,9H                   ;Print out prompt message
  54.  
  55.         LEA     DX,COPY_MSG_1
  56.  
  57.         INT     21H
  58.  
  59.         MOV     CX,11                   ;Print out 11 letters of found file name
  60.  
  61.         MOV     BX,81H                  ;Point to match in default DTA
  62.  
  63.         MOV     AH,2
  64.  
  65. QLOOP:  MOV     DL,[BX]                 ;Get letter of found file's name
  66.  
  67.         INC     BX                      ;Point to next letter
  68.  
  69.         INT     21H
  70.  
  71.         LOOP    QLOOP                   ;Keep going until all 11 printed
  72.  
  73.         MOV     AH,9H                   ;Print out 2nd half of prompt message
  74.  
  75.         LEA     DX,COPY_MSG_2
  76.  
  77.         INT     21H
  78.  
  79.         MOV     AH,1                    ;Get a 1 character response
  80.  
  81.         INT     21H
  82.  
  83.         CMP     AL,'Y'                  ;Was it a 'Y'?
  84.  
  85.         JE      DO_COPY                 ;Yes, copy the file
  86.  
  87.         CMP     AL,'y'                  ;No...perhaps a 'y'?
  88.  
  89.         JE      DO_COPY                 ;Yes, copy the file
  90.  
  91.         JMP     NEXT                    ;Get next match (if none, leave)
  92.  
  93. DO_COPY:MOV     CX,37                   ;Using given target file as a template,
  94.  
  95.         LEA     SI,TARGET_FCB           ; load its 37 characters into the FCB
  96.  
  97.         MOV     DI,0C0H                 ; for use as real target FCB, checking
  98.  
  99.         CMP     BYTE PTR [SI+1],' '     ; for wildcards. First, was DRIVE: given
  100.  
  101.         JNE     NLOOP                   ; as target? No, check wildcards.
  102.  
  103.         PUSH    DI                      ;Yes, fill Target_FCB with wildcard ?'s 
  104.  
  105.         PUSH    CX                      ; so found filename will be used
  106.  
  107.         LEA     DI,TARGET_FCB
  108.  
  109.         INC     DI
  110.  
  111.         MOV     CX,11                   ;Put in 11 ?'s
  112.  
  113.         MOV     AL,'?'
  114.  
  115. REP     STOSB                           ;Do the fill
  116.  
  117.         POP     CX                      ;Restore counter and dest. pointer
  118.  
  119.         POP     DI
  120.  
  121. NLOOP:  MOV     BX,0                    ;Move given target name into real used
  122.  
  123.         CMP     BYTE PTR [SI],'?'       ; target FCB at 0C0H. If a wildcard is 
  124.  
  125.         JNE     CHAR_OK                 ; found in given filename use corres-
  126.  
  127.         MOV     BX,80H                  ; ponding character in found filename
  128.  
  129.         SUB     BX,OFFSET TARGET_FCB    ;Wildcard found, adjust source (SI) to
  130.  
  131.         ADD     SI,BX                   ; point to the found filename
  132.  
  133. CHAR_OK:MOVS    [DI],[SI]
  134.  
  135.         SUB     SI,BX                   ;Restore SI if necessary
  136.  
  137.         LOOP    NLOOP                   ;Loop back until for all 11 name char.s
  138.  
  139.         MOV     DX,80H                  ;Target FCB now at 0C0H, source at 80H
  140.  
  141.         MOV     AH,0FH                  ;Use DOS service 15 to open source
  142.  
  143.         INT     21H                     ;Open source FCB
  144.  
  145.         MOV     DX,0C0H                 ;Use DOS service 12 to create target
  146.  
  147.         MOV     AH,16H
  148.  
  149.         INT     21H                     ;Create target FCB (or if the file 
  150.  
  151.         AND     END_FLAG,0              ; already exists, zero it and refill it)
  152.  
  153.         MOV     BX,80H + 14
  154.  
  155.         MOV     WORD PTR [BX],8000H     ;Set record size for source (32K)
  156.  
  157.         MOV     BX,80H + 16             ;Get file size from opened source FCB
  158.  
  159.         MOV     AX,[BX]
  160.  
  161.         MOV     FILE_SIZE_LO,AX         ;Store low word of size in FILE_SIZE_LO
  162.  
  163.         ADD     BX,2                    ;Point to high word
  164.  
  165.         MOV     DX,[BX]
  166.  
  167.         MOV     FILE_SIZE_HI,DX         ;Store high word of size in FILE_SIZE_HI
  168.  
  169.         MOV     CX,1024                 ;Div DX:AX (High:Low of size) by 1024
  170.  
  171.         DIV     CX
  172.  
  173.         MOV     FILE_SIZE_K,AX          ;Get file size in rounded-up K (1024)
  174.  
  175.         TEST    DX,0FFFFH               ;Was it an even K file:Mod(size,1024)=0?
  176.  
  177.         JZ      ROUND                   ;Yes, don't add cluster for file remnant
  178.  
  179.         INC     FILE_SIZE_K             ;No, add 1 more cluster for remainder
  180.  
  181. ROUND:  MOV     BX,0C0H + 14
  182.  
  183.         MOV     WORD PTR [BX],400H      ;Set record size for target (1K)
  184.  
  185. READ:   LEA     DX,DATA_POINT           ;Set up the 32K DTA we'll use
  186.  
  187.         MOV     AH,1AH                  ; at the end of this program
  188.  
  189.         INT     21H                     
  190.  
  191.         MOV     DX,80H                  ;Point to source FCB to prepare for read
  192.  
  193.         MOV     AH,14H
  194.  
  195.         INT     21H                     ;Do the read of 32K bytes
  196.  
  197.         CMP     AL,0                    ;AL = 0 if end of file not yet reached
  198.  
  199.         JLE     READ_OK
  200.  
  201.         OR      END_FLAG,1              ;Have read in the whole file, DTA is
  202.  
  203. READ_OK:MOV     CX,20H                  ; stuffed with zeroes after end of file
  204.  
  205.         LEA     DX,DATA_POINT           ;Reset our offset into 32K DTA to the
  206.  
  207.         MOV     DTA_OFFSET,DX           ; start
  208.  
  209. WLOOP:  MOV     DX,0C0H                 ;Point to target FCB, prepare for write
  210.  
  211.         MOV     AH,15H
  212.  
  213.         INT     21H                     ;Do the write 1K at a time
  214.  
  215.         CMP     AL,0                    ;Was the write a success?
  216.  
  217.         JE      COPY_OK                 ;Yes, check if done writing
  218.  
  219.         LEA     DX,FULL_MSG             ;No, assume the disk was full and say so
  220.  
  221.         MOV     AH,9H                   ;Print error string
  222.  
  223.         INT     21H
  224.  
  225.         JMP     OUT                     ;Exit 
  226.  
  227. COPY_OK:DEC     FILE_SIZE_K             ;Decrement number of clusters to write
  228.  
  229.         JZ      FINISH                  ;Done?
  230.  
  231.         ADD     DTA_OFFSET,400H         ;No, point to next 1K chunk of DTA
  232.  
  233.         MOV     DX,DTA_OFFSET           
  234.  
  235.         MOV     AH,1AH                  ;Set DTA to match
  236.  
  237.         INT     21H
  238.  
  239.         LOOP    WLOOP                   ;Repeat until 32K written or end of file
  240.  
  241.         TEST    END_FLAG,1              ;Have we read in the end of file?
  242.  
  243.         JZ      READ                    ;No, get next 32K block from source
  244.  
  245. FINISH: MOV     AX,FILE_SIZE_LO         ;Now adjust written file's size
  246.  
  247.         MOV     BX,0C0H + 16            ;Point to low word of size
  248.  
  249.         MOV     WORD PTR [BX],AX        ;And set it to the correct value
  250.  
  251.         ADD     BX,2                    ;Point to high word of size
  252.  
  253.         MOV     AX,FILE_SIZE_HI         ;And set it too
  254.  
  255.         MOV     WORD PTR [BX],AX
  256.  
  257.         MOV     AH,10H                  ;Request DOS service 16, close files
  258.  
  259.         MOV     DX,0C0H                 ;Point to target file's FCB
  260.  
  261.         INT     21H                     ;Close target with correct size
  262.  
  263.         MOV     DX,80H                  ;Point to source file's FCB
  264.  
  265.         INT     21H                     ;Close source
  266.  
  267. NEXT:   MOV     DX,80H                  ;Start looking for the next match
  268.  
  269.         MOV     AH,1AH          ;First, reset DTA to 80H for found file's FCB
  270.  
  271.         INT     21H             
  272.  
  273.         MOV     AH,12H                  ;Now search for next match-service 18
  274.  
  275.         MOV     DX,5CH                  ;Use given filename to match to
  276.  
  277.         INT     21H
  278.  
  279.         CMP     AL,0                    ;Match found?
  280.  
  281.         JNE     OUT                     ;No, exit.
  282.  
  283.         JMP     QUERY                   ;Yes, ask if it should be copied
  284.  
  285. OUT:    RET
  286.  
  287.  
  288.  
  289. MOVE    ENDP
  290.  
  291. DATA_POINT:                             ;The 32K DTA starts here
  292.  
  293. CODE_SEG        ENDS
  294.  
  295.         END     FIRST                   ;'END FIRST' so entry point set to FIRST
  296.  
  297.  
  298.  
  299.